package com.zl.console.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zl.common.dto.ResDTO;
import com.zl.common.enums.resp.GlobalRespEnum;
import com.zl.common.utils.ReturnUtil;

@Controller
public class zlogin{
    @Value("${console.loginKeys:autocode}")
    private String loginKeys;
    @Value("${console.loginCheck:true}")
    private boolean loginCheck;
    @Value("${console.loginUrl:/error}")
    private String loginUrl;
    
    @RequestMapping(value="${console.loginUrl:/error}")
    public String login( HttpServletRequest request, ModelMap map) throws Exception{
        String http = request.getRequestURL().toString().replace(request.getServletPath(), "");
        map.addAttribute("httpStr", http);
        return "page/login";
    }
    @RequestMapping(value="/login")
    @ResponseBody
    public Object loginCheck(String password) throws Exception{
        if(loginCheck){
            if(!loginKeys.equals(password)){
                return ReturnUtil.returnDATA(GlobalRespEnum.TOKEN_INVALID_EXCEPTION,null);
            }
        }
        return ReturnUtil.successDATA(null);
    }
    @PostMapping(value="/error")
    @ResponseBody
    public ResDTO<Object> error() throws Exception{
        return ReturnUtil.returnDATA(GlobalRespEnum.NOT_FOUND,null);
    }
}